<template>
  <ConfigForm :configs="createForm" :server="litServer" :beforeSubmit="beforeSubmit" />
</template>

<script setup lang="jsx">
import { litServer } from '@/api/arrears'
import ConfigForm from '@/components/CRUD/ConfigForm.vue'
import CourtSelect from '@/views/Court/components/CourtSelect.vue'
import LawyerSelect from '@/views/Court/components/LawyerSelect.vue'

const props = defineProps({
  info: {
    type: Object,
    default: () => ({})
  },
})

const createForm = [
  {
    label: '法院',
    key: 'court',
    type: 'custom',
    required: true,
    props: { placeholder: '请选择开庭法院', isObject: true, },
    render: CourtSelect,
  },
  {
    label: '法庭',
    key: 'court_number',
    type: 'input',
    required: true,
    props: { placeholder: '请输入法庭' },
  },
  {
    label: '审级',
    key: 'level',
    type: 'select',
    required: true,
    options: [
      { label: '一审', value: '一审' },
      { label: '二审', value: '二审' },
      { label: '再审', value: '再审' },
    ],
    props: { placeholder: '请选择审级' },
  },
  {
    label: '开庭时间',
    key: 'open_datetime',
    type: 'datepicker',
    required: true,
    props: { placeholder: '请选择开庭时间', type: 'datetime', valueFormat: 'YYYY-MM-DD HH:mm:ss' },
  },
  {
    label: '出庭律师',
    key: 'open_court_user',
    type: 'custom',
    required: true,
    dynamicProps: (form) => {
      return {
        openDatetime: form.open_datetime,
      }
    },
    render: LawyerSelect,
  },
]

const beforeSubmit = (params) => {
  params.arrears_data_id = props.info.arrears_data_id;
  params.open_court_user_id = params.open_court_user.user_id;
  delete params.open_court_user;
  params.court_id = params.court.court_id;
  params.court_name = params.court.name;
  delete params.court;
  return params
}
</script>